<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>设备借出审核</title>
    <#include "../../common/link.ftl">
    <script>
        $(function () {
            // 归还申请
            $(".leadBtn").click(function () {
                var hot = $(this).data("hot");
                var id = $(this).data("id");
                $.get("/deviceRecord/applyReturn.do", {hot:hot, id:id}, function (data) {
                    if(data.code == 200){
                        window.location.reload();
                    }else{
                        $.messager.alert("温馨提示", data.msg);
                    }
                })
            })

            // 查看申请理由
            $(".reasonBtn").click(function () {
                //数据复原
                $("#editForm").clearForm(true);

                var json = $(this).data('json');
                if(json){
                    $("textarea[name='reason']").val(json.reason);
                }
                $("#inputSynModal").modal('show');
            })

            // 借出审核
            $(".agreeBtn").click(function () {
                //数据复原
                $("#editForm1").clearForm(true);

                var json = $(this).data('json');
                if(json){
                    var id = json.id;
                    $("#editForm1 input[name='id']").val(id);
                    $("#editForm1 input[name='deviceId']").val(json.deviceId);
                    $("#editForm1 input[name='number']").val(json.number);
                    var isAgree = json.isAgree;
                    if(isAgree == 0){
                        $("#agreeApply").prop("checked",true);
                    }
                    if(isAgree == 1){
                        $("#agreeYes").prop("checked",true);
                    }
                    if(isAgree == 2){
                        $("#agreeNo").prop("checked",true);
                    }
                    $("textarea[name='agreeRefuse']").val(json.agreeRefuse);
                }
                $("#myModal").modal('show');
            })

            // 保存
            $(".btn-submit").click(function () {
                //使用jquery-form插件来提交异步表单(有表单时会使用该插件,写的代码比较少)
                $("#editForm1").ajaxSubmit(handlerMessage)
            })

            // 归还审核
            $(".returnBtn").click(function () {
                //数据复原
                $("#editForm2").clearForm(true);

                var json = $(this).data('json');
                if(json){
                    var id = json.id;
                    $("#editForm2 input[name='id']").val(id);
                    $("#editForm2 input[name='deviceId']").val(json.deviceId);
                    $("#editForm2 input[name='number']").val(json.number);
                    $("#editForm2 input[name='isAgree']").val(json.isAgree);
                    var isReturn = json.isReturn;
                    if(isReturn == 0){
                        $("#returnApply").prop("checked",true);
                    }
                    if(isReturn == 1){
                        $("#returnYes").prop("checked",true);
                    }
                    if(isReturn == 2){
                        $("#returnNo").prop("checked",true);
                    }
                    $("textarea[name='returnRefuse']").val(json.returnRefuse);
                }
                $("#myModal2").modal('show');
            })

            // 保存
            $(".btn-submit2").click(function () {
                //使用jquery-form插件来提交异步表单(有表单时会使用该插件,写的代码比较少)
                $("#editForm2").ajaxSubmit(handlerMessage)
            })

            //删除按钮
            $(".btn-delete").click(function () {
                //获取当前点击的部门id
                var id = $(this).data('id');
                //提示确认框
                $.messager.confirm("警告","是否确认删除?",function () {
                    //发送ajax请求
                    $.get('/deviceRecord/delete.do',{id:id},handlerMessage)
                })
            })
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="LendReturnAdmin"/>
    <#include "../../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>设备借还审核</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 10px;">
                    <form class="form-inline" id="searchForm" action="/deviceRecord/admin/list.do" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label for="keyword">关键字：</label>
                            <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}" placeholder="请输入设备/社团/负责人">
                        </div>
                        &nbsp;
                        <div class="form-group">
                            <label for="leadStatus"> 借用：</label>
                            <select class="form-control" id="leadStatus" name="leadStatus">
                                <option value="-1">全部</option>
                                <option value="0">申请中</option>
                                <option value="1">借用成功</option>
                                <option value="2">借用失败</option>
                            </select>
                            <script>
                                $("#leadStatus").val(${qo.leadStatus!});
                            </script>
                        </div>
                        &nbsp;
                        <div class="form-group">
                            <label for="returnStatus"> 归还：</label>
                            <select class="form-control" id="returnStatus" name="returnStatus">
                                <option value="-1">全部</option>
                                <option value="0">申请中</option>
                                <option value="1">已归还</option>
                                <option value="2">未归还</option>
                            </select>
                            <script>
                              $("#returnStatus").val(${qo.returnStatus!});
                            </script>
                        </div>

                        <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>
                        <a href="/deviceRecord/input.do" class="btn btn-success btn_redirect">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    </form>
                </div>
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>设备名称</th>
                        <th>借用数量</th>
                        <th>社团名称</th>
                        <th>负责人</th>
                        <th>联系方式</th>
                        <th>申请时间</th>
                        <th>申请理由</th>
                        <th>是否同意借用</th>
                        <th>借用时间</th>
                        <th>借用审核</th>
                        <th>是否已经归还</th>
                        <th>归还时间</th>
                        <th>归还审核</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <#list page.list as deviceRecord>
                        <tr>
                            <td>${deviceRecord_index+1}</td>
                            <td>${deviceRecord.deviceName!}</td>
                            <td>${deviceRecord.number!}</td>
                            <td>${deviceRecord.association!}</td>
                            <td>${(deviceRecord.dutyName)!}</td>
                            <td>${(deviceRecord.mobile)!}</td>
                            <td>${(deviceRecord.applyTime?string('yyyy-MM-dd HH:mm:ss'))!}</td>
                            <td>
                                <a class="reasonBtn" href="JavaScript:;" data-json='${deviceRecord.jsonString!}'>申请理由
                                </a>
                            </td>

                            <td>
                                <#if (deviceRecord.isAgree!) == 0>
                                    申请中
                                </#if>
                                <#if (deviceRecord.isAgree!) == 1>
                                    是
                                </#if>
                                <#if (deviceRecord.isAgree!) == 2>
                                    否
                                </#if>
                            </td>
                            <td>${(deviceRecord.lendingTime?string('yyyy-MM-dd HH:mm:ss'))!}</td>
                            <td>
                                <a class="btn btn-primary btn-xs agreeBtn" href="javascript:;" data-json='${deviceRecord.jsonString!}'>
                                    <span class="glyphicon glyphicon-star-empty"></span> 借用审核
                                </a>
                            </td>
                            <td>
                                <#if (deviceRecord.isReturn!) == 0>
                                    申请中
                                </#if>
                                <#if (deviceRecord.isReturn!) == 1>
                                    是
                                </#if>
                                <#if (deviceRecord.isReturn!) == 2 || (deviceRecord.isReturn!) == 3 >
                                    否
                                </#if>
                            </td>
                            <td>${(deviceRecord.returnTime?string('yyyy-MM-dd  HH:mm:ss'))!}</td>
                            <td>
                                <a class="btn btn-success btn-xs returnBtn" href="javascript:;"  data-json='${deviceRecord.jsonString!}'>
                                    <span class="glyphicon glyphicon-star"></span> 归还审核
                                </a>
                            </td>
                            <td>
                                <#--<a class="btn btn-success btn-xs leadBtn" href="javascript:;" data-id='${deviceRecord.id}' data-hot="0">-->
                                    <#--<span class="glyphicon glyphicon-minus-sign"></span> 申请归还-->
                                <#--</a>-->
                                <a href="/deviceRecord/input.do?id=${deviceRecord.id}" class="btn btn-info btn-xs btn_redirect">
                                    <span class="glyphicon glyphicon-pencil"></span> 编辑
                                </a>
                                <a href="javascript:;" class="btn btn-danger btn-xs btn-delete" data-id="${deviceRecord.id}">
                                    <span class="glyphicon glyphicon-trash"></span> 删除
                                </a>
                            </td>
                        </tr>
                    </#list>
                </table>
                <!--分页-->
                <#include "../../common/page.ftl">
            </div>
        </section>
    </div>
    <#include "../../common/footer.ftl">
</div>

<!-- Modal模态框 -->
<div class="modal fade" id="inputSynModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalSynLabel">申请理由</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="" method="post" id="editForm">
                    <div class="form-group">
                        <div class="col-sm-12">
                            <textarea rows="10" style="min-width: 100%" name="reason"></textarea>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">借用审核</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/deviceRecord/agreeLeading.do" method="post" id="editForm1">
                    <input type="hidden" name="id">
                    <input type="hidden" name="deviceId">
                    <input type="hidden" name="number">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sex" class="col-sm-3 control-label">状态：</label>
                        <div class="col-sm-6">
                            <input type="radio" id="agreeApply" name="isAgree" value="0" />申请中
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" id="agreeYes" name="isAgree" value="1" />同意
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" id="agreeNo" name="isAgree" value="2" />拒绝
                        </div>
                    </div>

                    <#--<#if isAgree == 2>-->
                        <div class="form-group" style="margin-top: 10px;">
                            <label for="agreeRefuse" class="col-sm-3 control-label">拒绝理由：</label>
                            <div class="col-sm-6">
                                <textarea class="form-control" name="agreeRefuse" id="agreeRefuse"></textarea>
                            </div>
                        </div>
                    <#--</#if>-->
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title2" id="myModalLabel2">归还审核</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/deviceRecord/agreeReturn.do" method="post" id="editForm2">
                    <input type="hidden" name="id">
                    <input type="hidden" name="deviceId">
                    <input type="hidden" name="number">
                    <input type="hidden" name="isAgree">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sex" class="col-sm-3 control-label">状态：</label>
                        <div class="col-sm-6">
                            <input type="radio" id="returnApply" name="isReturn" value="0" />申请中
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" id="returnYes" name="isReturn" value="1" />同意
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" id="returnNo" name="isReturn" value="2" />拒绝
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="returnRefuse" class="col-sm-3 control-label">拒绝理由：</label>
                        <div class="col-sm-6">
                            <textarea class="form-control" name="returnRefuse" id="returnRefuse"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit2">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
